package com.etrans.web.gps.business.report.controller;

import java.net.URLDecoder;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.etrans.web.gps.base.controller.BaseController;
import com.etrans.web.gps.business.gis.domain.Track;
import com.etrans.web.gps.business.report.service.OtherProvinceVeService;
import com.etrans.web.gps.util.Config;

/**
 * 外省车辆入黔
 * @author jw.chen
 *
 */
@Controller
@RequestMapping("/report/otherProvinceVe/*")
public class OtherProvinceVeController extends BaseController{
	
	@Autowired
	private OtherProvinceVeService otherProviceVeService;
	@Autowired
	private Config config; //引用统一的参数配置类 
	
	/**
	 * 页面跳转入口
	 * @return
	 */
	@RequestMapping(value="getOtherProvinceVe.html")
	public String getAlarmSynAnalysis(HttpServletRequest request, Model model){
		HashMap<String, Object> param = getReqParameters();
		Integer menuId = StringUtils.isNumeric(param.get("menuId")+"")?Integer.valueOf(param.get("menuId")+""):1583;
		model.addAttribute("menuName", otherProviceVeService.getMenuNameById(menuId));
		model.addAttribute("addressPath", config.addressPath);
		return "views/business/report/otherProvinceVe";
	}

	/**
	 * 查询车辆总数和在线数
	 */
	@ResponseBody
	@RequestMapping(value = "getAllOnlineCount.html")
	public  HashMap<String,Object> getAllOnlineCount() {
		try {
			return otherProviceVeService.getAllOnlineCount();
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * 外省车辆监控树
	 */
	@ResponseBody
	@RequestMapping(value = "loadVehicleTree.html")
	public  HashMap<String,Object> loadVehicleTree(String vehicle_no) {
		try {
			return otherProviceVeService.getVehicleTreeJsonResult(vehicle_no);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}
	
	/**
	 * @Description 订阅车辆
	 * @param vehicle_no_color 车牌号_车牌颜色
	 * @throws Exception 
	 */
	@RequestMapping("subScribe.html")
	@ResponseBody
	public List<Track> subScribe(String vehicle_no_color) throws Exception{
		if(vehicle_no_color == null || "".equals(vehicle_no_color)){
			return null;
		}
		String no_color = URLDecoder.decode(vehicle_no_color, "utf-8");
		return otherProviceVeService.getSubScribe(no_color.split(","));
	}
	
//	/**
//	 * 根据车牌号查询外省车辆
//	 * @return 车辆信息和在线状态
//	 */
//	@ResponseBody
//	@RequestMapping(value = "queryOtherProVeByNo.html")
//	public HashMap<String,Object> queryOtherProVeByNo(String paramsGrid) {
//		Map<String, Object> params = FlexiGridUtil.parseJSONParam(paramsGrid).getWhereParam();		
//		HashMap<String,Object> resultMap = new HashMap<String,Object>();
//		String vehicle_no = String.valueOf(params.get("vehicle_no"));
//		List<OtherProvinceVeVO> otherProVeList = otherProviceVeService.queryOtherProVeByNo(vehicle_no);
//		resultMap.put("rows", otherProVeList);
//		return resultMap;
//	}
}
